from manimlib import *
from numpy import flip, insert

LV,QL,QH,JH='#75cfb8','#bbdfc8','#f0e5d8','#ffc478'

class p1(Scene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.5)
        ab=Line(LEFT,RIGHT).scale(1.3).shift(UP)
        high=4
        # tan 80=h/x
        cd=ab.copy().set_length(ab.get_length()+2*high*np.tan(np.pi/18)).shift(DOWN*high)
        a,b,c,d=ab.get_left(),ab.get_right(),cd.get_right(),cd.get_left()
        ad,bc=Line(a,d),Line(b,c)
        t_mid=VGroup(ab,bc,cd,ad)
        t_left=t_mid.copy().rotate(-20*DEGREES).next_to(a+DOWN*high,UL,buff=0)
        t_right=t_mid.copy().rotate(20*DEGREES).next_to(b+DOWN*high,UR,buff=0)
        angle_a=Angle(ad,ab)
        angle_b=Angle(Line(b,a),Line(b,c))
        angle_c=Angle(Line(c,b),Line(c,d))
        angle_d=Angle(cd,Line(d,a))
        self.add(t_mid,t_left,t_right,angle_d,angle_a,angle_b,angle_c,
            Tex('\cdots').scale(5).rotate(-40*DEGREES).next_to(t_left,UL,buff=-0.3),
            Tex('\cdots').scale(5).rotate(40*DEGREES).next_to(t_right,UR,buff=-0.3),
            Tex('100^\circ').next_to(angle_a,DR),
            Tex('100^\circ').next_to(angle_b,DL),
            Tex('80^\circ').next_to(angle_c,UL),
            Tex('80^\circ').next_to(angle_d,UR),
        )
        self.wait()

class p2(Scene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.5)
        ab=Line(LEFT,RIGHT).scale(1.3).shift(UP)
        high=4
        # tan 80=h/x
        cd=ab.copy().set_length(ab.get_length()+2*high*np.tan(np.pi/18)).shift(DOWN*high)
        a,b,c,d=ab.get_left(),ab.get_right(),cd.get_right(),cd.get_left()
        ad,bc=Line(a,d),Line(b,c)
        t_mid=VGroup(ab,bc,cd,ad).scale(0.31).to_edge(DOWN)
        for i in range(18):
            t=t_mid.copy()
            self.add(
                t.rotate_about_origin(20*DEGREES*i),
                Tex(str(i+1)).move_to(t.get_center())
                )
        self.wait()

class p3(Scene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.5)
        ab=Line(LEFT,RIGHT).scale(1.3).shift(UP+LEFT*1.5)
        high=4
        # tan 80=h/x
        cd=ab.copy().set_length(ab.get_length()+2*high*np.tan(np.pi/18)).shift(DOWN*high)
        a,b,c,d=ab.get_left(),ab.get_right(),cd.get_right(),cd.get_left()
        ad,bc=Line(a,d),Line(b,c)
        t_mid=VGroup(ab,bc,cd,ad)
        t_left=t_mid.copy().rotate(-20*DEGREES).next_to(a+DOWN*high,UL,buff=0)
        t_right=t_mid.copy().rotate(20*DEGREES).next_to(b+DOWN*high,UR,buff=0)
        angle_a=Angle(ad,ab)
        angle_b=Angle(Line(b,a),Line(b,c))
        angle_c=Angle(Line(c,b),Line(c,d))
        angle_d=Angle(cd,Line(d,a))
        self.add(t_mid,t_right,angle_d,angle_a,angle_b,angle_c,
            Tex('100^\circ').next_to(angle_a,DR),
            Tex('100^\circ').next_to(angle_b,DL),
            Tex('80^\circ').next_to(angle_c,UL),
            Tex('80^\circ').next_to(angle_d,UR),
        )
        # p3
        f=t_right.get_boundary_point(RIGHT)
        g=t_right.get_corner(DR)
        angle_80=Angle(Line(c,f),Line(c,b))
        angle_20=Angle(Line(c,g),Line(c,f))
        self.add(angle_80,angle_20,Line(c,g),
            Tex('80^\circ').next_to(angle_80,UR),
            Tex('20^\circ').next_to(angle_20).shift(RIGHT*0.5+UP*0.13)
        )
        self.wait()

